package com.zaizai.controller;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.zaizai.domain.AjaxResult;
import com.zaizai.service.IAiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 与ai的交互Controller
 */
@RestController
@RequestMapping("/ai")
@Slf4j
public class AiController {
    @Autowired
    private IAiService aiService;

    /**
     *向ai发送消息
     */
    @PostMapping("/send")
    public AjaxResult aiTalk(@RequestBody String question) throws NoApiKeyException, InputRequiredException {
        return AjaxResult.success(aiService.toTalkResult(question));
    }
}